import db from "../connector/db";
import log from "../log";

/**
 * The `userId` is the logged-in user's id.
 *
 * You should make sure that they is invalid.
 */
async function agree({ userId, agreement }: { userId: string; agreement: string }): Promise<void> {
  await db.userAgreed.upsert({
    where: { pk: { userId, agreement } },
    update: { latestAgreeTime: new Date() },
    create: { userId, agreement, latestAgreeTime: new Date(), firstAgreeTime: new Date() },
  });
}

const agreementService = {
  agree,
};

export default agreementService;
